from django.shortcuts import render, HttpResponse, Http404
try:
    from crf.crf_seg import crf_seg, crf_seg_init
    crf_seg_init('crf/model')
    using_crf = True
except:
    using_crf = False
# Create your views here.



def index(requests):
    return render(requests, 'index.html')

def seg(request):
    if request.method == 'GET':
        sentence = request.GET['data']
        if using_crf:
            data = crf_seg(sentence)
        else:
            data = '服务器未配置crf++'
        return HttpResponse(data)
    return Http404()